package com.hsc.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hsc.commonutils.R;
import com.hsc.eduservice.entity.EduCourse;
import com.hsc.eduservice.entity.EduTeacher;
import com.hsc.eduservice.service.EduChapterService;
import com.hsc.eduservice.service.EduCourseService;
import com.hsc.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin //gateway解决了可以注掉
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    /**
     * 查询名师与热门课程
     * @return
     */
    @GetMapping("index")
    public R index(){
        //查询前八热门课程
        QueryWrapper<EduCourse> wrapperCourse = new QueryWrapper<>();
        wrapperCourse.orderByAsc("id");
        wrapperCourse.last("limit 8");
        List<EduCourse> eduCourses = courseService.list(wrapperCourse);

        //查询前4个名师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByAsc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> eduTeachers = teacherService.list(wrapperTeacher);

        return R.ok().data("eduList",eduCourses).data("teacherList",eduTeachers);


    }

}
